/**
 * Created by sqw on 2017/7/16.
 */

/**
 * 从JSON对象生成JSON Array，用于From的POST提交
 * 示例
 * @param model
 * @param prefix
 */
function getJSONArrayFromObject(model,prefix){
    if(prefix==null) prefix = "t";
    var json = new Array();
    for(var key in model){
        if(model[key] instanceof  Array){
            var ids = model[key]
            ids.forEach(function(item,index){
                if(item instanceof  Object)
                    json.push({name:prefix+"."+key+".id", value: item.id})
                else
                    json.push({name:prefix+"."+key+".id", value: item})
            })
        }else  if(model[key] instanceof  Object){
            var obj = model[key]
            json.push({name:prefix+"."+key+".id",value: obj.id });
        }else{
            json.push({name:prefix+"."+key,value:model[key]});
        }
    }
    return json;
}